package com.xhl.shiro.modules.admin.controller;

import com.gitee.fastmybatis.core.PageInfo;
import com.gitee.fastmybatis.core.query.Query;
import com.xhl.shiro.base.R;
import com.xhl.shiro.modules.admin.entity.SysUserEntity;
import com.xhl.shiro.modules.admin.param.SysUserParam;
import com.xhl.shiro.modules.admin.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户管理")
@RestController
@RequestMapping("/m/sysUser")
public class SysUserController extends AbstractController{
    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;


    /**
     * 分页查询
     * @param userName
     * @return
     */
    @GetMapping("/token")
    public R token(String userName) {
        return R.ok();
    }

    @ApiOperation("分页查询")
    /**
     * 分页查询
     * @param param
     * @return
     */
    @GetMapping("/page")
    public R page(SysUserParam param) {
        Query query = param.toQuery();

        PageInfo<SysUserEntity> pageInfo = sysUserService.page(query);
        return R.ok().put("data", pageInfo);
    }

    @ApiOperation("菜单保存")
    /**
     * 保存
     * @param sysUser
     * @return
     */
    @PostMapping("/save")
    public R save(SysUserEntity sysUser) {
        sysUserService.saveIgnoreNull(sysUser);
        return new R().ok().put("data", sysUser.getUserId());
    }


    /**
     * 更新
     * @param sysUser
     * @return
     */
    @GetMapping("/update")
    public R update(SysUserEntity sysUser) {
        sysUserService.updateIgnoreNull(sysUser);
        return R.ok();
    }

    /**
     * 删除
     * @param userId
     * @return
     */
    @GetMapping("/delete")
    public R delete(Integer userId) {
        sysUserService.deleteById(userId);
        return R.ok();
    }
}
